package io.noties.markwon.base.core.factory

import io.noties.markwon.base.MarkwonConfiguration
import io.noties.markwon.base.RenderProps
import io.noties.markwon.base.SpanFactory
import io.noties.markwon.base.core.CoreProps
import io.noties.markwon.base.core.spans.BulletListItemSpan
import io.noties.markwon.base.core.spans.OrderedListItemSpan

class ListItemSpanFactory : SpanFactory {
    override fun getSpans(configuration: MarkwonConfiguration, props: RenderProps): Any {

        // type of list item
        // bullet : level
        // ordered: number
        val spans= if (CoreProps.ListItemType.BULLET == CoreProps.LIST_ITEM_TYPE.require(props)) {
                BulletListItemSpan(
                    configuration.theme,
                    CoreProps.BULLET_LIST_ITEM_LEVEL.require(props)
                )
            } else {
                // todo| in order to provide real RTL experience there must be a way to provide this string
                val baseNum = CoreProps.ORDERED_LIST_ITEM_NUMBER.require(props)
                val numberStr=configuration.defaultOrderIndex.getIndexString(baseNum)
                val number = "$numberStr. "
                OrderedListItemSpan(
                    configuration.theme,
                    number
                )
            }
        return spans
    }
}